package com.desiy.pojo.dto;

import lombok.Data;

/**
 * @author Desiy
 * @date 2020/5/13 16:34
 */
@Data
public class ResponseDTO {
    /**
     * 返回的消息
     */
    private String msg;
    /**
     * 返回错误的消息
     */
    private String errorMsg="操作失败";
    /**
     * 返回成功的消息
     */
    private String successMsg="操作成功";
    /**
     *返回的结果
     */
    private Boolean res;
    /**
     * 返回的数据
     */
    private Object data;
    /**
     * 状态码：401未授权   404路径错误    500代码异常   400请求错误
     */
    private Integer status;

    public ResponseDTO(String msg, String errorMsg, String successMsg, Boolean res, Object data, Integer status) {
        this.msg = msg;
        this.errorMsg = errorMsg;
        this.successMsg = successMsg;
        this.res = res;
        this.data = data;
        this.status = status;
    }
    public ResponseDTO(String msg, Boolean res, Object data, Integer status) {
        this.msg = msg;
        this.res = res;
        this.data = data;
        this.status = status;
    }
    public ResponseDTO(String msg, Boolean res, Object data) {
        this.msg = msg;
        this.res = res;
        this.data = data;
    }
    /**
     * 成功
     * @return
     */
    public static ResponseDTO ok(String msg, Object data){
        return new ResponseDTO(msg,true,data);
    }
    /**
     * 重载
     * 成功
     * @return
     */
    public static ResponseDTO ok(String msg){
        return new ResponseDTO(msg,true,null);
    }
    /**
     * 失败
     */
    public static ResponseDTO fail(String msg, Object data){
        return new ResponseDTO(msg,false,data);
    }
    /**
     * 重载
     * 失败
     */
    public static ResponseDTO fail(String msg){
        return new ResponseDTO(msg,false,null);
    }

    /**
     * 根据从过来的结果去获取返回对象
     * @param res
     * @return
     */
    public static ResponseDTO get(Boolean res){
        return new ResponseDTO(null,res,null);
    }
}
